﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace NeedForSmash
{
    class Battlefield : DrawableGameComponent
    {
        private Game m_game;
        public Game GameCore
        {
            get
            {
                return this.m_game;
            }
            private set
            {
                m_game = value;
            }
        }

        protected List<Element> ElementList;

        private Vector3 Position = Vector3.One;
        private Matrix gameWorldRotation = Matrix.Identity;

        KeyboardState oldState;

        protected World m_world;

        public Battlefield(Game game)
            : base(game)
        {
            GameCore = game;
            ElementList = new List<Element>();
            m_world = new World(game);
        }

        public override void Initialize()
        {
            oldState = Keyboard.GetState();
            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            UpdateInput();
            m_world.Update(gameTime);
        }

        private void UpdateInput()
        {
            KeyboardState newState = Keyboard.GetState();

#if DEBUG
            if (newState.IsKeyDown(Keys.Q))
            {
                GameCore.Camera.Position -= new Vector3(1, 0, 0);
            }
            else if (newState.IsKeyDown(Keys.D))
            {
                GameCore.Camera.Position += new Vector3(1, 0, 0);
            }
            else if (newState.IsKeyDown(Keys.Z))
            {
                GameCore.Camera.MoveForward();
            }
            else if (newState.IsKeyDown(Keys.S))
            {
                GameCore.Camera.MoveBackward();
            }
#endif
            oldState = newState;
        }
    }
}
